package com.fg.pro.trade.controller;



import com.fg.pro.model.reponse.ResponseResult;
import com.fg.pro.trade.service.TradeStockService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;

/**
 * 商品_货值(TradeStock)表控制层
 *
 * @author makejava
 * @since 2025-08-20 10:10:15
 */
@RestController
@RequestMapping("tradeStock")
public class TradeStockController {
    /**
     * 服务对象
     */
    @Resource
    private TradeStockService tradeStockService;

    /**
     *  上传入库文件excel表格
     * @param multipartFile
     * @return
     */
    @Operation(summary = "上传库存报表",description = "参数为导入选择的时间")
    @PostMapping("/upload")
    public ResponseResult upload(@RequestParam(value = "file") MultipartFile multipartFile,
                                           @RequestParam(required = false)@DateTimeFormat(pattern = "yyyy-MM-dd") Date date){
        Boolean flag = tradeStockService.upload(multipartFile,date);
//        return flag?ResponseResult.okResult("导入成功"):ResponseResult.errorResult(UPLOAD_ERROR);
        return ResponseResult.okResult(flag?"刷新成功":"正在刷新中。。。");
    }

    @Operation(summary = "获取出入库分页信息",description = "参数为商品名称")
    @GetMapping("/getPage")
    public ResponseResult getPage(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                                                  @RequestParam(required = false,defaultValue = "10") Integer pageSize,
                                                  @RequestParam(required = false)@DateTimeFormat(pattern = "yyyy-MM-dd") Date start,
                                                  @RequestParam(required = false)@DateTimeFormat(pattern = "yyyy-MM-dd") Date end,
                                                  @RequestParam(required = false) String goodsName){
        PageInfo pageInfo = tradeStockService.getPage(pageNum,pageSize,start,end,goodsName);
        return ResponseResult.okResult(pageInfo);
    }

}

